<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
	</head>

	<body>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view mui-table-view-chevron">

				</ul>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/utils/httpUtils.js"></script>
		<script>
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载111...',
						callback: pullupRefresh
					}
				}
			});
			console.log("init over!");
			//初始化http工具
			var http_utils = new HttpUtils(mui.os.plus);
			var url = "wxhh/get_all_player_list"
			// 下拉刷新回调
			var pulldownRefreshCallback = function(response) {
				var code = response.code;
				if(code == 200){
					ret = response.ret
					ret = ret.reverse()
					console.log(ret);
					var table = document.body.querySelector('.mui-table-view');

					for (var i = 0;  i < ret.length; i++) {
						var li = document.createElement('li');
						li.className = 'mui-table-view-cell';
						li.innerHTML = '<div class="mui-table">'+
		                '<div class="mui-table-cell mui-col-xs-10">'+
		                    '<h4 class="mui-ellipsis-2">'+
		                    "账号："+ret[i].name+
		                    '</h4>'+
		                    '<h5>'+"昵称："+ret[i].nick_name+" 金币："+ret[i].gold+'</h5>'+
		                    '<p class="mui-h6 mui-ellipsis">'+
		                    "最后登录时间："+ret[i].modified_date
		                    '</p>'+
		                '</div>'+
		                '<div class="mui-table-cell mui-col-xs-2 mui-text-right">'+
		                    '<span class="mui-h5">'+ret[i].modified_date+'</span>'+
		                '</div>'+
		            '</div>'
//						li.innerHTML = '<a class="mui-navigate-right"> ' + 
//						(ret[i].name)+";"+
//						ret[i].nick_name+";"+
//						ret[i].gold+
//						'</a>';
						//下拉刷新，新纪录插到最前面；
						table.insertBefore(li, table.firstChild);
					}
				};
			};
			// 页面初始化回调
			var plusReadyCallback = function(response){
				
			};
				/**
				 * 下拉刷新具体业务实现
				 */
			function pulldownRefresh() {
				setTimeout(function() {
					http_utils.get(url, {}, pulldownRefreshCallback, http_utils.errorCB)
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					for (var i = cells.length, len = i + 3; i < len; i++) {
						var li = document.createElement('li');
						li.className = 'mui-table-view-cell';
						li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>';
						//下拉刷新，新纪录插到最前面；
						table.insertBefore(li, table.firstChild);
					}
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
				}, 1500);
			}
			var count = 0;
			/**
			 * 上拉加载具体业务实现
			 */
			function pullupRefresh() {
				setTimeout(function() { 
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					for (var i = cells.length, len = i + 20; i < len; i++) {
						var li = document.createElement('li');
						li.className = 'mui-table-view-cell';
						li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>';
						table.appendChild(li);
					}
				}, 1500);
			}


			if (mui.os.plus) {
				mui.plusReady(function() {
					console.log("当前页面URL："+plus.webview.currentWebview().getURL());
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 1000); 
					http_utils.get(url, {}, plusReadyCallback, http_utils.errorCB)
					console.log(mui.os.plus);
				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
					http_utils.get(url, {}, plusReadyCallback, http_util.errorCB)
					console.log("else!");
				});
			}
		</script>
	</body>

</html>